<?php

class Internetua_com extends Grabber_Abstract
{
	protected $_count_grab_news = 1;
	protected $_translate_text = true;

	protected function _parsingList( $html )
	{
		$links = array();
		$matched = $this->_match('<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>', $html);

		if( !empty( $matched[1] ) && !empty( $matched[2] ) )
		{
			foreach( $matched[1] as $key => $value )
			{
				$links[$matched[2][$key]] = $value;
			}
		}
		
		return $links;
	}
	
	protected function _nextListPage( $html )
	{
		$matched = $this->_match('<div class="pager pagertop zoom">.*<ul>.*<li class="active">[\r\n\t]*.*<a href="(.*)">.*</a>', $html);
	
		if( !empty( $matched[1] ) && !empty( $matched[1][0] ) )
		{
			return $matched[1][0];
		}
		
		return false;
	}
	
	/**
	 * Парсит html, витягивает полную статью
	 *
	 * @param type $html - string
	 * @return array('news'=>string, 'comments'=>array());
	 */
	protected function _getNews( $html )
	{
		$result = array( 'news' => '', 'title' => '', 'comments' => array() );

		$html = $this->_cutSpaces( $html );

		$pattern = '<h1>(.*)</h1>';
		$matched = $this->_match( $pattern, $html );

		if( !empty( $matched[1] ) && !empty( $matched[1][0] ) )
			$result['title'] = $matched[1][0];

		$pattern = '<div class="bcontent">(.*)</div>';
		$matched = $this->_match( $pattern, $html );
		
		if( !empty( $matched[1] ) && !empty( $matched[1][0] ) )
			$result['news'] = $matched[1][0];

		$pattern = '<div class="cbody">(.*)</div>';
		$matched = $this->_match( $pattern, $html );

		if( !empty( $matched[1] ) )
			$result['comments'] = $matched[1];

		return $result;
	}
	
}
